<{include file="Public/head.tpl"}>
<{include file="Public/header.tpl"}>
<{include file="Public/siderbar.tpl"}>
<{include file="Public/contentheader.tpl"}>

    <!-- Main content -->
    <section class="content">

      <div class="col-md-8">
        <!-- Horizontal Form -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title">请修改用户的信息</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal">
              <div class="box-body">
                <div class="form-group">
                  <label for="username" class="col-sm-2 control-label">用户名</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" id="username" value=<{$data->username}> readonly>
                  </div>
                </div>
                <div class="form-group">
                  <label for="email" class="col-sm-2 control-label">邮件地址</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" id="email" value=<{$data->email}>>
                  </div>
                </div>
                <div class="form-group">
                  <label for="roleid" class="col-sm-2 control-label">所属用户组</label>
                  <div class="col-sm-10">
                    <select class="form-control" id="roleid">
                      <{foreach $roledata as $role}>
                        <{if $role.id == $data->roleid}>
                          <option value=<{$role.id}> selected><{$role.name}></option>
                        <{else}>
                          <option value=<{$role.id}>><{$role.name}></option>
                        <{/if}>
                      <{/foreach}>
                    </select>
                  </div>
                </div>
                <div class="form-group">
                  <label for="status" class="col-sm-2 control-label">状态</label>
                  <div class="col-sm-10">
                    <select class="form-control" id="status">
                      <{if $data->status == 1}>
                        <option value="1" selected>启用</option>
                        <option value="0">禁用</option>
                      <{else}>
                        <option value="1">启用</option>
                        <option value="0" selected>禁用</option>
                      <{/if}>
                    </select>
                  </div>
                </div>
              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                <input type="hidden" id="id" value="<{$data->id}>" />
                <a href="/admin/power/list" class="btn btn-default">取消</a>
                <button type="button" class="btn btn-info pull-right" onclick="edit();">确定</button>
              </div>
              <!-- /.box-footer -->
            </form>
          </div>
          <!-- /.box -->
       </div>

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  
<{include file="Public/footer.tpl"}>
<script>
    function edit() {
      bootbox.setLocale("zh_CN");
	    var posturl = window.location.href;
      var email = document.getElementById("email").value;
      var roleid = document.getElementById("roleid").value;
      var status = document.getElementById("status").value;
      var id = document.getElementById("id").value;
  
      if (email == ''){
        bootbox.alert("邮件地址不能为空"); 
        return;
      }
      if (roleid == ''){
        bootbox.alert("所属角色组不能为空"); 
        return;
      }
  
      $.ajax({
        url : posturl,
        type : 'post',
        data : 'email=' + email
            + '&roleid=' + roleid
            + '&status=' + status
            + '&id=' + id,
        success : function(data) {
          var ret = JSON.parse(data);
          if (ret.status == 1) {
            bootbox.alert(ret.data);
            setTimeout(function(){window.location.href="/admin/user/list"}, 2000);
          } else {
            bootbox.alert(ret.data);
          }
        }
      });
    }
</script>
</body>
</html>